<?php if (!defined('THINK_PATH')) exit();?>

	<div class='margin-top50' style='margin-top:50px' >
		<div class=' center' style='text-align:center'>用户注册</div>
		<form actions='/index.php/User/User/register_c' method='post' >

			<div class='marginauto width150 margin-top30' style='margin:0 auto;width:150px;margin-top:30px' >
				<div class='margin-bottom10' style='margin-bottom:10px'>邮　箱： </div>
				<div>
					<input  name='register_email' />
				</div>
			</div>


			<div class='marginauto width150 margin-top10' style='margin:0 auto;width:150px;margin-top:10px'>
				<div class='margin-bottom10' style='margin-bottom:10px'>验证码： </div>
				<div>
					<input name='register_code' />
				</div>
			</div>
			<div style='margin:0 auto;width:150px;height:50px;margin-top:10px'>
				<img src='/index.php/User/User/vCode' style='width:100%;height:100%' onclick="this.src='/index.php/User/User/vCode?a='+Math.random()"/>
			</div>

			<div class='center margin-top20' style='text-align:center;margin-top:20px'>
				<button id='register_sub' type='button'>提交</button>
				<input type='reset' value='重置' />
			</div>

		</form>
		<div style='font-size:12px;text-align:center;margin-top:1px;margin-top:20px'>
			已有账户 
			<a onclick='Register_Back()' style='color:blue'><b>登陆</b>
		</div>
	</div>



<script>
	$('#register_sub').click(function(){
		var register_email = $('input[name=register_email]').val().trim();
		var register_code = $('input[name=register_code]').val().trim();
		if(!register_email || !register_code){
			alert('注册信息不得为空！');exit;
		}
		var register_p = /^\w+@\w+\.[a-z]{2,3}$/;
		if(!register_p.test(register_email)){
			alert('邮箱格式不正确！');exit;
		}
		$.ajax({
			url:'/index.php/User/User/register_c_ajax',			//直接去掉2，就可以
			type:'post',
			data:{
				token:'<?php echo Token_Set('register_c_ajax');?>',
				userName:register_email,
				vCode:register_code,
				module:sessionStorage.ModuleName
			},
			success:function(res){
				switch(res){
					case 'e1':
						alert('信息不得为空!');
						register();
					break;
					case 'e2':
						alert('请正确输入邮箱!');
						register();
					break;
					case 'e3':
						alert('验证码错误！');
						register();
					break;
					case 'e4':
						alert('信件发送太频繁，请休息一会儿！');
						register();
					break;
					case 'e5':
						alert('该邮箱以被注册');
						register();
					break;
					case 'e6':
						alert('系统异常，信件未发出！');
						register();
					break;
					case 'e7':
						alert('信件发出后数据异常，请联系管理员!');
						register();
					break;
					case 'ok':
						alert('已向您的邮箱发送了一封确认信，请查看并确认');
						register();
					break;
					default:
						alert('非法访问！');
						register();
				}
			}
		});

	});

	function register(){
		$.ajax({
			url:'/index.php/User/User/register',
			success:function(res){
				$('#content').html(res);
				sessionStorage.Register = escape(res);
			}
		});
	}
	
	//返回登陆
	function Register_Back(){
		if(sessionStorage.Page_Login){
			$('#content').html(unescape(sessionStorage.Page_Login));
		}else{
			$.ajax({
				url:'/index.php/User/User/login',
				success:function(res){
					$('#content').html(res);
				}
			});
		}
	}
</script>